package demo3;

import java.util.Stack;

public class Test4 {
    public static void main(String[] args) {

    }
}
class MinStack {
    Stack<Integer> stack;
    Stack<Integer> minStack;
    public MinStack () {
        stack = new Stack<>();
        minStack = new Stack<>();
    }
    public void push (int val) {
        stack.push(val);
        if (minStack.isEmpty()) {
            minStack.push(val);
        } else {
            int k = minStack.peek();
            if (k >= val) {
                minStack.push(val);
            }
        }
    }
    public void pop () {
        int k = stack.pop();
        if (!minStack.empty() && k == minStack.peek()) {
            minStack.pop();
        }
    }
    public int top () {
        return stack.peek();
    }
    public int getMin () {
        return minStack.peek();
    }
}